package com.micro.turtle.runner;

import cn.hutool.core.collection.CollectionUtil;
import com.micro.turtle.anon.CmdRunner;
import com.micro.turtle.constant.Cmd;
import com.micro.turtle.constant.Url;
import com.micro.turtle.constant.Url.ProjectUri;
import com.micro.turtle.model.Project;
import com.micro.turtle.util.Api;
import com.micro.turtle.util.Log;
import java.util.List;

/**
 * ProjectRunner
 *
 * @author jason.lv
 * @since 2022/1/20 16:23
 */
public class ProjectRunner {

    @CmdRunner
    public static class ListRunner extends Runner {

        public ListRunner() {
            super(Cmd.PROJECTS);
        }

        @Override
        void exec() {
            String next = scannerNext("输入项目组ID:");
            print(list(Integer.valueOf(next)));
        }
    }

    public static void print(List<Project> projects) {
        if (CollectionUtil.isEmpty(projects)) {
            Log.info("Projects >>>>> has nothing");
            return;
        }
        for (Project project : projects) {
            Log.info("Project >>>>> Id:%s||| %s ||| %s", project.getId(),project.getName(), project.getDescription());
        }
    }

    public static List<Project> list(Integer groupId) {
        Url url = Url.create(ProjectUri.LIST).group(groupId);
        return Api.getList(url, Project.class);
    }

    public static Project detail(Integer projectId) {
        Url url = Url.create(ProjectUri.DETAIL).project(projectId);
        return Api.get(url, Project.class);
    }

}
